package tt.dz.biz.service.user;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.user.UserServiceDAO;
import tt.dz.common.LogUtil;
import tt.dz.vo.UserBaseVO;
import tt.dz.vo.UserServiceVO;

@Service("userServiceService")
public class UserServiceService
{
  @Resource(name="userServiceDAO")
  UserServiceDAO userServiceDAO;
  
  public boolean batchModifyUserService(List<UserServiceVO> userServiceList, String userId)
  {
    boolean excuteFlag = true;
    try
    {
      this.userServiceDAO.deleteUserService(userId);
      int[] iArray = this.userServiceDAO.batchModifyUserService(userServiceList);
      for (int i : iArray) {
        if (i < 0)
        {
          excuteFlag = false;
          break;
        }
      }
    }
    catch (Exception e)
    {
      excuteFlag = false;
      LogUtil.error("批量更新用户可用服务异常", e);
    }
    return excuteFlag;
  }
  
  public List<UserServiceVO> queryUserServiceByUser(UserBaseVO userBaseVO)
  {
    List<UserServiceVO> userServiceList = null;
    try
    {
      userServiceList = this.userServiceDAO.queryUserServiceByUser(userBaseVO);
    }
    catch (Exception e)
    {
      LogUtil.error("根据用户查询用户可用服务列表异常", e);
      userServiceList = new ArrayList();
    }
    return userServiceList;
  }
  
  public int[] batchInsertUserService(List<UserServiceVO> userServiceList)
    throws Exception
  {
    try
    {
      return this.userServiceDAO.batchInsertUserService(userServiceList);
    }
    catch (Exception e)
    {
      LogUtil.error("批量插入用户默认可用服务异常,参数userServiceList为：" + userServiceList, e);
      throw e;
    }
  }
}
